// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function mark_for_destroy(element) { 
  $(element).parentNode.next('.should_destroy').value = 1 
  $(element).up('.note_type').hide(); 
}

function fix_positions(){
	

	cols = document.getElementsByName("ticket_template[note_type_attr][][col_number]");
	pris = document.getElementsByName("ticket_template[note_type_attr][][priority]");
	
	var col_num = 0;

	for (i=0; i<pris.length; i++){
		if (cols[i].parentNode.parentNode.id == "note_types1") col_num = 1;
		if (cols[i].parentNode.parentNode.id == "note_types2") col_num = 2;
		pris[i].value = i;
		cols[i].value = col_num;
	}
	
}


//next function needed to set false values for unchecked checkboxes
function set_checkboxes(){
    var tmp;
    notes = document.getElementsByName("ticket[notes_attr][][value]");
    for (i=0; i<notes.length; i++){
		if ((notes[i].type == "checkbox") && (!notes[i].checked) )
                {
                    tmp = document.createElement('input');
                    tmp.name='ticket[notes_attr][][value]';
                    tmp.type='hidden';
                    tmp.value='false';
//                      document.createElement("<INPUT type='123' />");
                    notes[i].parentNode.appendChild(tmp);
                }
    }
}

function show_or_hide_select_text(element){
	if (element.selectedIndex == 4) {
		tmp = $(element).next('.select_text');
		if (tmp != nil) {tmp.appear()} else {$(element).next('.fieldWithErrors').appear()}
	} else {
//		$(element).next('.select_text').hide();
		tmp = $(element).next('.select_text');
		if (tmp != nil) {tmp.hide()} else {$(element).next('.fieldWithErrors').hide()}
	}	
}
